package com.zhouyu;

import com.zhouyu.service.UserInterface;
import com.zhouyu.service.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxyDemo {
	public static void main(String[] args) {
		UserService target = new UserService();
		UserInterface o = (UserInterface) Proxy.newProxyInstance(JdkProxyDemo.class.getClassLoader(), new Class[]{UserInterface.class}, new InvocationHandler() {
			@Override
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				System.out.println("before...");
				Object result = method.invoke(target, args);
				System.out.println("after...");
				return result;
			}
		});
		o.test();
	}
}
